package com.guigu.service.impl.stock;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.stock.SSecondProductAreaMapper;
import com.guigu.pojo.stock.SFirstProductArea;
import com.guigu.pojo.stock.SSecondProductArea;
import com.guigu.service.stock.SSecondProductAreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-25
 */
@Service
public class SSecondProductAreaServiceImpl extends ServiceImpl<SSecondProductAreaMapper, SSecondProductArea> implements SSecondProductAreaService {

    @Autowired
    private SSecondProductAreaMapper sSecondProductAreaMapper;

    @Override
    public Boolean insertSSecondProductArea(SSecondProductArea sSecondProductArea) {
        int r = sSecondProductAreaMapper.insert(sSecondProductArea);
        return r > 0;
    }

    @Override
    public PageInfo<SSecondProductArea> selectSecondFirst(HashMap<String, Object> map) {
        Integer pageNum = 1;
        Integer pageSize = 5;
        Object pageNumObj = map.get("pageNum");
        if (pageNumObj != null && StringUtils.isNotBlank((String) pageNumObj)) {
            pageNum = Integer.parseInt((String) pageNumObj);
        }
        Object pageSizeObj = map.get("pageSize");
        if (pageSizeObj != null && StringUtils.isNotBlank((String) pageSizeObj)) {
            pageSize = Integer.parseInt((String) pageSizeObj);
        }
        PageHelper.startPage(pageNum,pageSize);
        ArrayList<SSecondProductArea> sSecondProductAreas = sSecondProductAreaMapper.selectAllSecondPro();

        PageInfo<SSecondProductArea> pageInfo = new PageInfo<>(sSecondProductAreas);
        return pageInfo;

    }

    @Override
    public SSecondProductArea selectOne(String secondId) {
        QueryWrapper<SSecondProductArea> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("SECOND_ID",secondId);
        SSecondProductArea sSecondProductArea = sSecondProductAreaMapper.selectOne(queryWrapper);
        return sSecondProductArea;
    }
}
